﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace EntityFramework.Helper.Searcher
{
    public interface ISearcher<E> where E : System.Data.Objects.DataClasses.EntityObject
    {

        #region Fields

        /// <summary>
        /// Defines the context of the Persister.
        /// </summary>
        System.Data.Objects.ObjectContext Context
        {
            get;
            set;
        }

        PropertyInfo ContextEntityProperty
        {
            get;
            set;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Returns all the object of E <see cref="System.Data.Objects.DataClasses.EntityObject"/> type on the context.
        /// </summary>
        /// <returns>All E <see cref="System.Data.Objects.DataClasses.EntityObject"/> objects on the context.</returns>
        E[] FindAll();

        /// <summary>
        /// Returns all the object of E <see cref="System.Data.Objects.DataClasses.EntityObject"/> type on the context ordered by the indicated field.
        /// </summary>
        /// <param name="orderBy">Order by field.</param>
        /// <returns>All E <see cref="System.Data.Objects.DataClasses.EntityObject"/> objects on the context, ordered by the field.</returns>
        E[] FindAll(string orderBy = "asc");
        
        /// <summary>
        /// Returns all the objects that match the parameter criteria.
        /// </summary>
        /// <param name="criteria">The search criteria.</param>
        /// <returns>The objects that match the parameter criteria.</returns>
        E[] FindAll(ICriteria<E> criteria);

        /// <summary>
        /// Returns the first object of the context.
        /// </summary>
        /// <returns>The first object object of the context.</returns>
        E FindFirst();
        
        /// <summary>
        /// Returns the first object that matches the criteria.
        /// </summary>
        /// <param name="criteria">The search criteria.</param>
        /// <returns>The first object that matches the criteria.</returns>
        E FindFirst(ICriteria<E> criteria);
        
        /// <summary>
        /// Returns only one object that matches the criteria.
        /// </summary>
        /// <param name="criteria">The search criteria.</param>
        /// <returns>Only one object that matches the criteria.</returns>
        /// <exception cref="">Throws this exceptiopn when the search criteria matches with more than one object.</exception>
        E FindOne(ICriteria<E> criteria);

        #endregion

    }
}
